const mysql = require('mysql2');

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'Zhao5162300..0',
  database: 'xxsg_db',
});

connection.connect((err: any) => {
  if (err) {
    console.log(err);
    return;
  }

  console.log('数据库连接成功');
  const insertQuery =
    'INSERT INTO config_hero (id, name, story, rarity, face, photo, avatar, hp, attack, defence, speed, skill1, skill2, skill3, skill4, skill5, skill6, can_get, talent1, talent2, talent3, talent4, talent5, talent6) VALUES ?';

  connection.query(
    insertQuery,
    [heros.map((hero: any) => Object.values(hero))],
    (err: any, result: { affectedRows: any }) => {
      if (err) {
        console.error('插入数据失败:', err);
        return;
      }

      console.log(`插入 ${result.affectedRows} 条数据.`);
    },
  );

  // 关闭连接
  connection.end();
});
